#include<iostream>
#include<cstring>
using namespace std;
struct Exam
{
    int scoreNumber;
    string ansNum[3];
};

int my_Compare(const Exam* s1,const Exam* s2)
{//因为传进来的是结构体指针，是同一个地址的东西
//我不希望这个东西被更改，所以加一个Const
    for(int i=1;i<=3;i++)
    {
        int cntsame=0;
        string left=s1->ansNum[i-1];
        string right=s2->ansNum[i-1];
        int longLen=left.size()>=right.size()?left.size():right.size();
        int shortLen=left.size()<=right.size()?left.size():right.size();
        for(int j=0;j<shortLen;j++)
        {
            if(left[j]==right[j])
                cntsame++;
        }
        if((longLen*0.9-cntsame*1.0)<=0.000001 || (shortLen*0.9-cntsame*1.0)<=0.000001)
            return i;
    }
    return 0;
}


int main()
{
    int t;
    cin>>t;
    Exam* exams=new Exam[t];
    for(int i=0;i<t;i++)
    {
        cin>>exams[i].scoreNumber>>exams[i].ansNum[0]>>exams[i].ansNum[1]>>exams[i].ansNum[2];
    }
    for(int i=0;i<t-1;i++)
    {
        for(int j=i+1;j<t;j++)
        {
            int num=my_Compare(&exams[i],&exams[j]);
            if(num)
            {
                cout<<exams[i].scoreNumber<<" "<<exams[j].scoreNumber<<" "<<num<<endl;
            }
        }
    }
    //循环比较，两两传入结构体
    delete[] exams;
}